package com.jiaquyun.jcyx.main.mine

import androidx.lifecycle.LifecycleOwner
import androidx.recyclerview.widget.LinearLayoutManager
import com.blankj.utilcode.util.ActivityUtils
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.jiaquyun.jcyx.R
import com.jiaquyun.jcyx.entity.UserYongLog
import com.jiaquyun.jcyx.jetpack.mode.MineViewModel
import com.module.lemlin.http.Status
import com.module.lemlin.owner.OwnerViewModeActivity
import kotlinx.android.synthetic.main.activity_yong_details.*

class YongDetailsActivity : OwnerViewModeActivity<MineViewModel>() {

    companion object {
        fun open() {
            ActivityUtils.startActivity(YongDetailsActivity::class.java)
        }
    }


    private val mMoneyDetailsAdapter =
        object : BaseQuickAdapter<UserYongLog, BaseViewHolder>(R.layout.item_money_details) {
            override fun convert(holder: BaseViewHolder, item: UserYongLog) {
                holder.setText(R.id.tvMoneyDetailsName, item.remark)
                    .setText(R.id.tvMoneyDetailsTime, item.createtime)
                    .setText(R.id.tvMoneyDetailsPrice, item.money)
            }
        }

    override fun viewModel(): MineViewModel {
        return createViewModel()
    }

    override val layoutResId: Int
        get() = R.layout.activity_yong_details

    override fun stateBar(): StatusBar {
        return StatusBar(isLightMode = true, color = R.color.white, view = flYongDetailsBar)
    }

    override fun initData() {
        viewModel.userYongLog()
    }

    override fun initView() {

        ivAppBack.setOnClickListener { finish() }

        rvYongDetailsBody.apply {
            layoutManager = LinearLayoutManager(this@YongDetailsActivity)
        }.adapter = mMoneyDetailsAdapter

    }

    override fun initViewMode() {
        viewModel.userYongLogLiveDate.observe(this as LifecycleOwner, { response ->
            if (response.status != Status.SUCCESS) {
                return@observe
            }
            val data = response.data?.data
                ?: return@observe
            mMoneyDetailsAdapter.setNewInstance(data)
        })
    }

}